package com.yike.user.controller;

import com.yike.user.entity.UserCategory;
import com.yike.user.param.UserCategoryParam;
import com.yike.user.service.UserCategoryService;
import com.yike.user.vo.UserCategoryVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.UserCategoryPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户类型 控制器
 *
 * @author Sakura
 * @since 2024-10-31
 */
@Slf4j
@RestController
@RequestMapping("/platform/userCategory")
@Module("user")
@Api(value = "用户类型API", tags = {"平台用户类型"})
public class UserCategoryController extends BaseController {

    @Autowired
    private UserCategoryService userCategoryService;

    /**
     * 添加用户类型
     */
    @PostMapping("/add")
    @OperationLog(name = "添加用户类型", type = OperationLogType.ADD)
    @ApiOperation(value = "添加用户类型", response = ApiResult.class)
    public ApiResult<Boolean> addUserCategory(@Validated(Add.class) @RequestBody UserCategoryParam userCategoryParam) throws Exception {
        boolean flag = userCategoryService.saveUserCategory(userCategoryParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改用户类型
     */
    @PostMapping("/update")
    @OperationLog(name = "修改用户类型", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改用户类型", response = ApiResult.class)
    public ApiResult<Boolean> updateUserCategory(@Validated(Update.class) @RequestBody UserCategoryParam userCategoryParam) throws Exception {
        boolean flag = userCategoryService.updateUserCategory(userCategoryParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除用户类型
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除用户类型", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除用户类型", response = ApiResult.class)
    public ApiResult<Boolean> deleteUserCategory(@PathVariable("id") Long id) throws Exception {
        boolean flag = userCategoryService.deleteUserCategory(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取用户类型详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "用户类型详情", type = OperationLogType.INFO)
    @ApiOperation(value = "用户类型详情", response = UserCategoryVo.class)
    public ApiResult<UserCategoryVo> getUserCategory(@PathVariable("id") Long id) throws Exception {
        UserCategoryVo userCategoryVo = userCategoryService.getUserCategory(id);
        return ApiResult.ok(userCategoryVo);
    }

    /**
     * 用户类型分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "用户类型分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "用户类型分页列表", response = UserCategoryVo.class)
    public ApiResult<Paging<UserCategoryVo>> getUserCategoryPageList(@Validated @RequestBody UserCategoryPageParam userCategoryPageParam) throws Exception {
        Paging<UserCategoryVo> paging = userCategoryService.getUserCategoryPageList(userCategoryPageParam);
        return ApiResult.ok(paging);
    }

}

